﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using haptic.src.engine.design;
using Microsoft.Xna.Framework;

namespace haptic.src.engine.animation
{
    public interface IStateController : IInstanciable<IStateControllerInstance>
    {
        void Initialize();
    }

    public interface IStateControllerInstance
    {
        void Update(StateInstance oStateInst, GameTime oTime, AutomateInstance.Context oContext);
    }

    [Serializable]
    public class StateLoop : IStateController, IStateControllerInstance
    {
        #region Constructors
        public StateLoop() { }
        #endregion
        public IStateControllerInstance CreateInstance()
        {
            return this;
        }
        public void Initialize(){}
        public void Update(StateInstance oStateInst, GameTime oTime, AutomateInstance.Context oContext)
        {
            if (oStateInst.oState.m_fDuration > 0.0f)
                oStateInst.m_fCurrentTimeStep -= (float)(int)(oStateInst.m_fCurrentTimeStep / oStateInst.oState.m_fDuration) * oStateInst.oState.m_fDuration;
            else
                oStateInst.m_fCurrentTimeStep = 0.0f;
        }
    }

    [Serializable]
    public class StateStayOnLastFrame : IStateController, IStateControllerInstance
    {
        #region Constructors
        public StateStayOnLastFrame() { }
        #endregion
        public IStateControllerInstance CreateInstance()
        {
            return this;
        }
        public void Initialize() { }
        public void Update(StateInstance oStateInst, GameTime oTime, AutomateInstance.Context oContext)
        {
            if (oStateInst.m_fCurrentTimeStep > oStateInst.oState.m_fDuration)
                oStateInst.m_fCurrentTimeStep = oStateInst.oState.m_fDuration;
        }
    }
}
